package com.dhecp.project.system.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.system.domain.SysModuleFieldSet;
import com.dhecp.project.system.mapper.SysModuleFieldSetMapper;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import com.dhecp.project.system.service.SysModuleFieldSetService;

/**
 * 功能列设置	服务实现层
 * @author DH-lwl
 * @version 2019年11月18日
 */
@Service
public class SysModuleFieldSetServiceImpl implements SysModuleFieldSetService {
	
	@Autowired
	private SysModuleFieldSetMapper moduleFieldSetMapper;
	
	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;

	/**
	 * 根据功能表名查询功能列设置字段列表
	 * @param params
	 * @return List-ModuleFieldSet
	 * @author lwl
	 * @throws Exception 
	 */
	@Override
	public List<SysModuleFieldSet> queryModuleFieldSetByTableName(Map<String, Object> params) throws Exception {
		String oldModuleTable="";
		if(params.get("moduleTable")!=null)oldModuleTable=params.get("moduleTable").toString();
		params.put("trueTable",true);
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));
		PageUtils.startPage();
		params.put("moduleTable",oldModuleTable);
		return moduleFieldSetMapper.findModuleFieldSetByTableName(params);
	}

	/**
	 * 根据guid查询字段功能列设置列表
	 * @param params
	 * @return 实体SysModuleFieldSet
	 * @author lwl
	 */
	@Override
	public SysModuleFieldSet queryModuleFieldSetByGuid(String guid) {
		return moduleFieldSetMapper.findModuleFieldSetByGuid(guid);
	}

	/**
	 * 修改功能列设置
	 * @param moduleFieldSetItems
	 * @return MessageModel
	 * @author DH-lwl
	 */
	@Override
	public AjaxResult updateModuleFieldSet(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<SysModuleFieldSet> dictList = JSON.parseArray(params.get("moduleFieldSetItems").toString(), SysModuleFieldSet.class);
		if (dictList == null || dictList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		for (SysModuleFieldSet moduleFieldSet : dictList) {
			moduleFieldSetMapper.updateModuleFieldSet(moduleFieldSet);
		}
		return AjaxResult.success("操作成功！");
	}
	
}
